package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;


public interface BookMapper extends BaseMapper<Book> {
    @Select("SELECT book_isbn, " +
            "MAX(name) AS name, " +  // 按业务选合适聚合函数，若同isbn下name唯一，MAX、MIN效果一样
            "MAX(author) AS author, " +
            "MAX(photo) AS photo, " + // 对photo用聚合函数，解决ONLY_FULL_GROUP_BY限制
            "MAX(borrownum) AS borrownum " +
            "FROM book " +
            "GROUP BY book_isbn " +
            "ORDER BY borrownum DESC " +
            "LIMIT 10")
    List<Book> getBorrowRank();

    @Select("SELECT name,category FROM book")
    List<Book> getAllBooks();

    @Select("SELECT * FROM book WHERE book_isbn = #{bookIsbn}")
    List<Book> getBooksByBookIsbn(String bookIsbn);

}
